package com.zqq.base.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.gyf.immersionbar.ImmersionBar;

public class StatusBarUtils {

    public static void setStatusBarTransparent(Activity activity){
        ImmersionBar.with(activity).statusBarDarkFont(false).init();
    }


    public static void setStatusBarTransparent1(Activity activity){
        ImmersionBar.with(activity).statusBarDarkFont(true).init();
    }

    public static void setStatusBarLight(Activity activity, int color, View view){
        ImmersionBar.with(activity)
                .statusBarColor(color)     //状态栏颜色，不写默认透明色
                .titleBarMarginTop(view)     //解决状态栏和布局重叠问题，任选其一
                .statusBarDarkFont(false)   //状态栏字体是深色，不写默认为亮色
                .init();
    }

    public static void setStatusBar(Activity activity, int color, View view){
        ImmersionBar.with(activity)
                .statusBarColor(color)     //状态栏颜色，不写默认透明色
                .titleBarMarginTop(view)     //解决状态栏和布局重叠问题，任选其一
                .statusBarDarkFont(true)   //状态栏字体是深色，不写默认为亮色
                .init();
    }


    /**
     * 设置状态栏背景白色 字体黑色
     *
     * @param activity
     * @param view
     */
    public static void setStatusBarWhite(Activity activity, View view) {
        setStatusBar(activity, android.R.color.white, view, true);
    }

    /**
     * 设置状态栏字体颜色
     *
     * @param activity 当前页面
     * @param color    要设置的颜色
     * @param view     根布局
     * @param isDark   是否是黑色字体
     */
    public static void setStatusBar(Activity activity, int color, View view, boolean isDark) {
        ImmersionBar.with(activity)
                .statusBarColor(color)     //状态栏颜色，不写默认透明色
                .titleBarMarginTop(view)     //解决状态栏和布局重叠问题，任选其一
                .statusBarDarkFont(isDark)   //状态栏字体是深色，不写默认为亮色
                .init();
    }

    /**
     * 沉浸式使用 沉浸式状态下布局会顶到状态栏，用于设置布局位置，使状态栏不覆盖布局
     */
    public static void setMargintTopStatusBar(Activity activity,View view) {
        StatusBarUtils.setStatusBarTransparent1(activity);
        int statusBarHeight = getStatusBarHeight(activity);
        LogUtils.i("bl_status","statusBarHeight>>${statusBarHeight}");
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.height = statusBarHeight;
        view.setLayoutParams(layoutParams);
    }


    /**
     * 沉浸式使用 沉浸式状态下布局会顶到状态栏，用于设置布局位置，使状态栏不覆盖布局
     */
    public static void setPaddingTopStatusBar(Activity activity,View view) {
        StatusBarUtils.setStatusBarTransparent1(activity);
        int statusBarHeight = getStatusBarHeight(activity);
        LogUtils.i("bl_status","statusBarHeight>>${statusBarHeight}");
        view.setPadding(0,statusBarHeight,0,0);
    }

    /**
     * 获取状态栏高度
     */
    private static int getStatusBarHeight(Context context){
        int statusBarHeight = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
        }
        return statusBarHeight;
    }
}
